package fi.roose.uidesignia.ui;

import fi.roose.uidesignia.R;
import fi.roose.uidesignia.data.DataModel;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		
		DataModel.initDummyData();
		
		Button design1  = (Button) findViewById(R.id.btn_design1);
		Button design2  = (Button) findViewById(R.id.btn_design2);
		
		design1.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				launch(Design1.class);
			}
		});
		
		
		design2.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				launch(Design2.class);
			}
		});
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}
	
	private void launch(Class<?> clazz){
		EditText edit = (EditText) findViewById(R.id.txt_virtualname);
		String name = edit.getText().toString().trim();
		name = DataModel.setVirtualName(name);
		if(name == null){
			AlertDialog.Builder b = new AlertDialog.Builder(this);
			b.setMessage("Provide virtual person name");
			b.setTitle("Failure");
			b.show();
			return;
		}
		
		Intent i = new Intent(MainActivity.this, clazz);
		startActivity(i);
		
	}

}
